﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TextLog.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Testing.Threading
{
    using System.Globalization;
    using System.Text;

    public class TextLog
    {
        private readonly StringBuilder _buffer = new StringBuilder();

        public TextLog AppendFormat(string format, params object[] args)
        {
            return Append(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public TextLog Append(string text)
        {
            lock (_buffer)
            {
                _buffer.Append(text);
            }

            return this;
        }

        public string Text
        {
            get
            {
                lock (_buffer)
                {
                    return _buffer.ToString();
                }
            }
        }

        public void Clear()
        {
            lock (_buffer)
            {
                _buffer.Length = 0;
            }
        }
    }
}